/**
 * 系统平台
 * moonvip_admin
 * com.tz.web.comment
 * CommentController.java
 * 创建人:小胡
 * 时间：2017年01月18日 10:25:33
 *
 */
package com.tz.web.comment;

import com.tz.auth.AuthPassport;
import com.tz.bean.Comment;
import com.tz.bean.TzParams;
import com.tz.service.comment.ICommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;

/**
 * 商城评价管理web
 * CommentController
 * 创建人:小胡
 * 时间：2017年01月18日 10:25:33
 * @version 1.0.0
 * 
 */
@Controller
@RequestMapping("/admin/shop/comment")
public class CommentController {
	
	@Autowired
	private ICommentService commentService;

	/*列表查询*/
	@AuthPassport
	@RequestMapping("/list")
	public String list(TzParams params){
		return "shop/comment/list";
	}

    /*模板页面*/
	@RequestMapping("/template")
	public String template(TzParams params ,Model model){
		model.addAttribute("datas", commentService.findComments(params));
		model.addAttribute("itemCount", commentService.count(params));
		return "shop/comment/template";
	}

	@AuthPassport
	@RequestMapping("/add")
	public String add(TzParams params){
		return "comment/add";
	}

	@AuthPassport
	@RequestMapping(value = "/edit/{id}" ,method = RequestMethod.GET)
	public String edit(@PathVariable("id") Integer id , Model model){
		HashMap<String ,Object> comment = commentService.getComment(id);
		model.addAttribute("comment",comment);
		return "shop/comment/edit";
	}

	@AuthPassport
	@ResponseBody
	@RequestMapping(value="/delete",method=RequestMethod.POST)
	public String delete(TzParams params){
		commentService.delete(params);
		return "success";
	}



	@ResponseBody
	@RequestMapping("/getPictures/{id}")
	public List<HashMap<String , Object>> getPictures(@PathVariable("id") Integer id , Model model){
		List<HashMap<String , Object>> pictures= commentService.getPictures(id);
		return  pictures;
	}

	@ResponseBody
	@RequestMapping(value="/update",method= RequestMethod.POST)
	public String update(Comment comment){
		commentService.update(comment);
		return "success";
	}
}
